package com.wedo.mall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.e.library.activity.EActivity;
import com.e.library.adapter.Adapter;
import com.e.library.adapter.EAdapter;
import com.wedo.mall.R;
import com.wedo.mall.activity.user.EvaluateActivity;
import com.wedo.mall.entity.GoodsList;
import com.wedo.mall.entity.OrderData;
import com.wedo.mall.util.WUrl;

import java.util.List;

/**
 * Created by Lawrence on 2017/8/10.
 */

public class GoodsListAdapter extends Adapter<GoodsList> {
    //（0.待支付，1.待发货，2.待收货，3.待评价，4.已完成，5.作废，6.退换货）
    Context context;
    OrderData orderData;

    public GoodsListAdapter(Context context, List<GoodsList> goodsLists,OrderData orderData) {
        super(context, goodsLists);
        this.context = context;
        this.orderData = orderData;
    }

    @Override
    protected int layout() {
        return R.layout.item_goodslistitem;
    }

    @Override
    protected void bind(EHolder holder, final GoodsList goodsList, int position) {
        ImageView iv_goodicon = holder.find(R.id.iv_goodicon);
        TextView tv_goodname = holder.find(R.id.tv_goodname);
        TextView tv_price = holder.find(R.id.tv_price);
        TextView tv_gooddescribe = holder.find(R.id.tv_gooddescribe);
        TextView tv_number = holder.find(R.id.tv_number);
        Button btn_evaluate = holder.find(R.id.btn_evaluate);

        Glide.with(mContext).load(WUrl.url(goodsList.goods_image)).error(R.drawable.place_holder_goods).placeholder(R.drawable.place_holder_goods).diskCacheStrategy(DiskCacheStrategy.ALL).into(iv_goodicon);
        tv_goodname.setText(goodsList.goods_name);
        tv_price.setText("RM"+goodsList.price);
        tv_gooddescribe.setText(goodsList.attr_list);
        tv_number.setText("X"+goodsList.goods_number);
        if(orderData.status.equals("3")){
            btn_evaluate.setVisibility(View.VISIBLE);
            btn_evaluate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    EvaluateActivity.toEvaluate((EActivity) context,orderData,goodsList);
                }
            });
        }else{
            btn_evaluate.setVisibility(View.GONE);
            btn_evaluate.setOnClickListener(null);
        }

    }
}
